package com.literaryfamily.literaryfamily.enumPackage;

import com.literaryfamily.literaryfamily.exceptions.OperationException;
import com.literaryfamily.literaryfamily.myUtil.StringUtil;

public enum OperatorStatic {
	UNPAID("待支付", 0),
	CLOSE("取消", 1),
	ERROR("支付失败", 2),
	ACCOMPLISH("已完成", 3);
	private final String staticName;
	private final int staticNum;

	public String getStaticName() {
		return staticName;
	}

	public int getStaticNum() {
		return staticNum;
	}

	OperatorStatic(String staticName, int staticNum) {
		this.staticName = staticName;
		this.staticNum = staticNum;
	}

	public static OperatorStatic getStaticName(String staticName) {
		if (StringUtil.isNull(staticName) || StringUtil.isNull(staticName.trim())) {
			throw new OperationException("没有找到对应操作类型");
		}
		staticName = staticName.trim();
		for (OperatorStatic operatorStatic : OperatorStatic.values()) {
			if (operatorStatic.getStaticName().equals(staticName)) {
				return operatorStatic;
			}
		}
		throw new OperationException("不存在的状态");
	}

	public static OperatorStatic getStaticNum(Integer staticNum) {

		if (staticNum == null) {
			throw new OperationException("没有找到对应操作类型");
		}
		int i = staticNum;
		for (OperatorStatic operatorStatic : OperatorStatic.values()) {
			if (operatorStatic.getStaticNum() == i) {
				return operatorStatic;
			}
		}
		throw new OperationException("不存在的状态");
	}
}